import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

// 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
const _import = require('./import-' + process.env.NODE_ENV)

export default new Router({
  scrollBehavior: () => ({ y: 0 }), // 每次跳转之后使页面跳转到顶部
  routes: [
    {
      path: '/',
      name: 'main',
      redirect: { name: 'home' },
      component: _import('main'),
      children: [
        {
          path: '/home',
          component: _import('pages/home'),
          name: 'home',
          meta: { title: '首页' }
        },
        {
          path: '/about',
          component: _import('pages/about'),
          name: 'about',
          meta: { title: '关于' }
        }
      ]
    },
    {
      path: '*',
      component: _import('404'),
      name: '404',
      meta: { title: '404' }
    }
  ]
})
